package day20170424.homework;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import org.junit.Test;

public class HomeWork06 {
	/**
	 * 6: 使用 OutputStreamWriter 把  把 "中深软通123" 写入曹io1704 BufferedWriter.txt
	 * @throws Exception
	 */
	@Test
	public void homework06(){
		//定义一个字节流
		OutputStream os = null;
		//定义一个字符流
		Writer writer = null;
		try {
			//拿到类路径
			File file = new File("txt/BufferedWriter.txt");
			os = new FileOutputStream(file);
			writer = new OutputStreamWriter(os);
			String str = "中深软通123作业06";
			//写入文件
			writer.write(str);
			writer.flush();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			if(null != writer){
				try {
					writer.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if(null != os){
				try {
					os.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
